#
# 根据用户选择，生成所需的标准项目结构
#
path = require 'path'
fs = require 'fs-extra'
Q = require 'q'
{exec} = require 'child_process'
{getResourcePath} = require '../utils/utils'


copyFile = (destPath, templateType, type) ->
  source = atom.packages.getActivePackage('atwork-qdt').path
  source = path.join(source, "frameworks");
  source = path.join(source, type);
  source = path.join(source, templateType);
  Q.Promise (resolve, reject, notify) ->
    #source = "g:\\a"
    #destPath = "g:\\b"
    console.log "cp from " , source
    console.log "to ", destPath
    platform = process.platform
    result = null;
    unless platform is 'win32'
      cmd = "cp -R #{source} #{destPath}"
    else
      cmd = 'xcopy ' + source + ' ' + destPath + '\\ /Ey'
    result = require("child_process").exec cmd, (err, stdout, stderr)->
      console.log "promise end", result.exitCode
      if err
        reject(error)
      else
        resolve(destPath)



module.exports = (options) ->
  destPath = path.resolve options.path, options.name
  console.log "going to cp file"
  copyFile destPath, options.template, options.type
  .then (path) ->
    console.log "cp file success , going to return #{path}"
    path
